home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
examples
/
libspool
/
queue.c.z
/
queue.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
5KB
|
185 lines
/**************************************************************************
* *
* Copyright (c) 1991 Silicon Graphics, Inc. *
* All Rights Reserved *
* *
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
* *
* The copyright notice above does not evidence any actual of intended *
* publication of such source code, and is an unpublished work by Silicon *
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
* the property of Silicon Graphics, Inc. Any use, duplication or *
* disclosure not specifically authorized by Silicon Graphics is strictly *
* prohibited. *
* *
* RESTRICTED RIGHTS LEGEND: *
* *
* Use, duplication or disclosure by the Government is subject to *
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
* Technical Data and Computer Software clause at DFARS 52.227-7013, *
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
* Supplement. Unpublished - rights reserved under the Copyright Laws of *
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
* Shoreline Blvd., Mountain View, CA 94039-7311 *
**************************************************************************
*
* File: queue.c
*
* Description: Prints the job queue for the specified printer.
*
**************************************************************************/
#ident "$Revision: 1.2 $"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef sgi
#include <getopt.h>
#endif
#include "spool.h"
char *pname;
int spooler = SL_SPOOLER_NONE; /* Indicate that no spooler is set */
int queue_type = SL_QUEUE_MERGED; /* Default to local + remote queue */
extern char *optarg;
extern int optind;
int queue_info(SLQueueStruct*); /* Display queue information */
void usage(char*);
main(int argc, char *argv[])
{
int i, ch, num, ret;
int errflag = 0;
SLPrinterStruct *ptr; /* Refer to SLGetPrinterList(3) */
SLQueueStruct *queue, *qptr; /* Refer to SLGetQueue(3) */
/*
* Process command line args
*/
while ((ch = getopt(argc, argv, "s:q:")) != -1) {
switch (ch) {
case 's': /* Spooler to use */
if (!strcmp(optarg, "bsd"))
spooler = SL_SPOOLER_BSD;
else if (!strcmp(optarg, "sysv"))
spooler = SL_SPOOLER_SYSV;
else
errflag++;
break;
case 'q': /* Queue type */
if (!strcmp(optarg, "local")) /* Local queue only */
queue_type = SL_QUEUE_LOCAL;
else if (!strcmp(optarg, "remote")) /* Remote queue only */
queue_type = SL_QUEUE_REMOTE;
else if (!strcmp(optarg, "merged")) /* Both queues */
queue_type = SL_QUEUE_MERGED;
else
errflag++;
break;
case '?':
default:
errflag++;
break;
}
}
/*
* If error, print usage and exit
*/
if (errflag) {
usage(argv[0]);
exit(1);
}
/*
* If a spooling system has been specified set it
*/
if (spooler != SL_SPOOLER_NONE) {
if (SLSetSpooler(spooler) < 0) {
SLPerror(argv[0]);
exit(1);
}
}
/*
* Get the printer name. If no printer name is specified, use
* the default printer
*/
if (argc == optind) {
if (SLGetDefPrinterName(&pname) < 0) {
SLPerror(argv[0]);
exit(1);
}
} else
pname = argv[optind];
/*
* Get the printer information. This is needed for SLGetQueue
*/
if (SLGetPrinterInfo(pname, &ptr) < 0) {
SLPerror(argv[0]);
exit(1);
}
/*
* Get the queue for this printer. If we get a SL_ERR_REMOTE
* error then we retry the call again in case the error was
* generated by transitory network problems.
*/
if ((ret = SLGetQueue(ptr, queue_type, &queue, &num)) < 0)
if (SLerrno == SL_ERR_REMOTE)
ret = SLGetQueue(ptr, queue_type, &queue, &num);
if (ret < 0) {
int j, status, nout;
char **out_buf;
SLPerror(argv[0]);
if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
(void)fprintf(stderr, "Spooler exit status: %d\n", status);
(void)fprintf(stderr, "Spooler error message(s):\n");
for (j = 0; j < nout; j++)
(void)fprintf(stderr, "\t%s\n", out_buf[j]);
}
exit(1);
}
/*
* Print the queue
*/
(void)printf("Queue for %s (%d jobs):\n", ptr->local_name, num);
for (i = 0, qptr = queue; i < num; i++, qptr++)
queue_info(qptr);
return 0;
}
int queue_info(SLQueueStruct *ptr)
{
(void)printf("\n");
(void)printf("\tJob ID:\t%s\n", ptr->job_id);
(void)printf("\tOwner:\t%s\n", ptr->username);
(void)printf("\tTitle:\t%s\n", ptr->title ? ptr->title : "Unknown");
(void)printf("\tSize:\t%u\n", ptr->size);
(void)printf("\tQueue:\t%s\n", (ptr->is_local) ? "local": "remote");
(void)printf("\tTime:\t%s", (ptr->time_stamp) ?
ctime(&ptr->time_stamp): "Unknown\n");
}
void usage(char *progname)
{
(void)fprintf(stderr,
"%s [-s bsd | sysv] [-q local | remote | merged] [printer_name]\n",
progname);
}